<template>
    <div>
        <el-card class="box-card queryCondition">
            <el-form :inline="true" :model="queryForm" size="mini">
                <el-form-item label="名称">
                    <el-input v-model="queryForm.name_like" placeholder="名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="query">查询</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <dol-list
                :url="url.list"
                :default-query-params="queryForm"
                :check-flag="false"
                title="<%= modelNameText %>列表"
                ref="list">
            <el-button slot="button" type="text" @click="add">
                <i class="el-icon-plus"></i>
            </el-button>
            <% var count = 0, key; %>
            <% for (key in field){if(!unLister[key]){ %>
            <el-table-column
                    prop="<%= key %>"
                    label="<%= nameFormatter[key] || key %>">
            </el-table-column>
            <% }} %>
            <el-table-column
                    prop="_id"
                    width="90px"
                    label="">
                <template slot-scope="scope">
                    <el-button slot="button" type="text" @click="detail(scope.row)">
                        <i class="fa fa-search"></i>
                    </el-button>
                    <el-button slot="button" type="text" @click="edit(scope.row)">
                        <i class="fa fa-edit"></i>
                    </el-button>
                    <el-button slot="button" type="text" @click="removeOne(scope.row._id)">
                        <i class="fa fa-trash"></i>
                    </el-button>
                </template>
            </el-table-column>
        </dol-list>
        <el-dialog
                title="<%= modelNameText %>维护"
                top="5vh"
                :visible.sync="editDialog">
            <el-form ref="form" :model="editForm" label-width="80px" size="small" class="editFrom">
                <el-row :gutter="10">
                    <% var count = 0, key; %>
                    <% for (key in field){if(!unEditor[key]){ %>
                    <el-col :span="12">
                        <el-form-item label="<%= nameFormatter[key] || key %>">
                            <el-input v-model="editForm.<%= key %>"></el-input>
                        </el-form-item>
                    </el-col>
                    <% }} %>
                </el-row>
            </el-form>

            <span slot="footer" class="dialog-footer">
                        <el-button @click="editDialog = false" size="small">取 消</el-button>
                        <el-button type="primary" @click="save" size="small">确 定</el-button>
                    </span>
        </el-dialog>
        <el-dialog
                title="<%= modelNameText %>详情"
                top="5vh"
                :visible.sync="detailDialog">
            <el-form :model="detailForm" label-width="80px" size="small" class="detailFrom">
                <el-row :gutter="10">
                    <% var count = 0, key; %>
                    <% for (key in field){if(!unDetail[key]){ %>
                    <el-col :span="12">
                        <el-form-item label="<%= nameFormatter[key] || key %>">
                            {{detailForm.<%= key %>}}
                        </el-form-item>
                    </el-col>
                    <% }} %>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                url: {
                    list: '<%= path.api %><%= path.route %>/list',
                    remove: '<%= path.api %><%= path.route %>/remove',
                    removeOne: '<%= path.api %><%= path.route %>/remove/{id}',
                    save: '<%= path.api %><%= path.route %>/save/{id}',
                    detail: '<%= path.api %><%= path.route %>/detail/{id}',
                    importData: '<%= path.api %><%= path.route %>/import',
                    exportData: '<%= path.api %><%= path.route %>/export',
                },
                queryForm: {},

                editDialog: false,
                editForm: {},
                detailDialog: false,
                detailForm: {},
                formId: '',
            };
        },
        computed: {},
        methods: {
            query() {
                this.$refs.list.query(this.queryForm);
            },
            add() {
                this.editForm = {};
                this.formId = '';
                this.editDialog = true;
            },
            edit(data) {
                this.editForm = Object.assign({}, data);
                this.formId = this.editForm._id;
                this.editDialog = true;
            },
            save() {
                this.$ajax({
                    url: this.url.save,
                    method: 'post',
                    data: this.editForm,
                    pathData: {id: this.formId},
                }).then(reData => {
                    this.editDialog = false;
                    this.$message(reData.message);
                    this.query();
                });
            },
            removeOne(id) {
                this.$ajax({
                    url: this.url.removeOne,
                    pathData: {id: id},
                }).then((reData) => {
                    this.$message(reData.message);
                    this.query();
                });
            },
            detail(data) {
                this.detailForm = data;
                this.detailDialog = true;
            },
        },
        created() {
        }
    }
</script>